package leetcode.code2028;

import java.util.Arrays;

import leetcode.IDebug;
import leetcode.helper.HelpDebug;

public class Solution implements IDebug {

	public int[] missingRolls(int[] rolls, int mean, int n) {
		int m = rolls.length;
		int total = (m + n) * mean;
		int sum = 0;
		for (int num : rolls) {
			sum += num;
		}
		int rest = total - sum;
		int avg = rest / n;
		int mod = rest % n;
		if (rest <= 0 || avg > 6 || avg <= 0 || (avg == 6 && mod != 0)) {
			return new int[] {};
		}

		int[] ans = new int[n];
		Arrays.fill(ans, avg);
		int p = 0;
		while (mod > 0) {
			ans[p++] += 1;// p++啊
			mod--;
		}
		return ans;
	}

	@Override
	public void debug4() {

		int[] ans = HelpDebug.str2array3("[4,4,4,4,4,4,5,5,4,4,4,5,4,4,4,4,4,4,4,4,5,5,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,5,5]");
		HelpDebug.compare(ans, this
				.missingRolls(HelpDebug.str2array3("[4,5,6,2,3,6,5,4,6,4,5,1,6,3,1,4,5,5,3,2,3,5,3,2,1,5,4,3,5,1,5]"), 4, 40));
	}

	@Override
	public void debug3() {

		int[] ans = HelpDebug.str2array3("[]");
		HelpDebug.compare(ans,
				this.missingRolls(HelpDebug.str2array3(
						"[4,2,2,5,4,5,4,5,3,3,6,1,2,4,2,1,6,5,4,2,3,4,2,3,3,5,4,1,4,4,5,3,6,1,5,2,3,3,6,1,6,4,1,3]"), 2,
						53));

		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
